package com.ys.sboot.hystrix.controller;


import com.ys.sboot.hystrix.arch.CommonHelloWorld;
import com.ys.sboot.hystrix.arch.ObservableCommondHelloWorld;
import com.ys.sboot.hystrix.service.NtqJobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rx.Observable;
import rx.Observer;

import java.util.ArrayList;
import java.util.List;


/**
 * 第一个熔断测试
 */
@RestController
@RequestMapping(value = "ntqJob")
public class NtqJobController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private NtqJobService ntqJobService;

    @GetMapping(value = "get")
    public String get() {

        CommonHelloWorld commonHelloWorld = new CommonHelloWorld("ys");
        String execute = commonHelloWorld.execute();
        return execute;

    }

    @GetMapping(value = "getList")
    public String getList() {

        List<String> list = new ArrayList<>();

        list.add("us");
        list.add("ys");
        ObservableCommondHelloWorld observableCommondHelloWorld = new ObservableCommondHelloWorld(list);
        Observable<String> observe = observableCommondHelloWorld.observe();
        observe.subscribe(new Observer<String>() {

            @Override
            public void onCompleted() {
                System.out.println("获取完了");
            }

            @Override
            public void onError(Throwable throwable) {
                throwable.printStackTrace();
            }

            @Override
            public void onNext(String s) {
                System.out.println(s);
            }


        });
        return "success";

    }
}
